package wyh.controller.Appointment;

import com.fasterxml.jackson.databind.ObjectMapper;
import wyh.pojo.Appointment;
import wyh.pojo.ServiceRecord;
import wyh.service.AppointmentService;
import wyh.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/Appointment/SelectByName")
public class SelectByNameLikeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ObjectMapper ojmapper = new ObjectMapper();
        Appointment pojo = new Appointment();
        // 从 URL 参数中获取 name
        int like = Integer.parseInt(req.getParameter("name"));
        pojo.setAppointmentId(like);
        AppointmentService service = new AppointmentService();
        Result result = null;
        Appointment po = service.ServicegetById(pojo.getAppointmentId());
        List<Appointment> list = new ArrayList<>();
        list.add(po);
        if (po!= null) {
            result = new Result(200, "查询到该模糊关键词", list);
        } else {
            result = new Result(500, "未查询到该模糊关键词", null);
        }
        String string = ojmapper.writeValueAsString(result);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(string);
    }
}